package org.yray.somehttp.js;

import org.mozilla.javascript.Context;
import org.mozilla.javascript.tools.SourceReader;
import org.mozilla.javascript.tools.shell.Global;
import org.mozilla.javascript.tools.shell.Main;

import java.io.IOException;

public class JavaRunJs {
    public static void main(String[] args) throws IOException {
        Context cx = Context.enter();
        String path="D:\\git_wk\\utools\\ufiletools\\src\\main\\resources\\aliplayer-min.js";
        Global scope = new Global(cx);
        cx.setOptimizationLevel(-1);
        cx.setLanguageVersion(Context.VERSION_1_7);
        String source = (String) SourceReader.readFileOrUrl(path, true, "GBK");
        Object o= Main.loadScriptFromSource(cx,source,path,1,null);
       /* Main.processFile(cx, scope, "D:\\git_wk\\utools\\ufiletools\\src\\main\\resources\\envjs\\platform\\require.js");
        Main.processFile(cx, scope, "D:\\git_wk\\utools\\ufiletools\\src\\main\\resources\\envjs\\platform\\core.js");
         */
        Main.processFile(cx, scope, "D:\\git_wk\\utools\\ufiletools\\src\\main\\resources\\envjs\\window.js");

        Main.processFile(cx, scope, path);

        //System.out.println(o);
        //System.out.println((String)cx.evaluateString(scope, "输入你要执行的js代码", "js", 1, null));
    }
}
